package com.amazon.controller;

import com.alibaba.fastjson.JSONObject;
import com.amazon.domain.User;
import com.amazon.params.AddUserParam;
import com.amazon.params.BasePageParam;
import com.amazon.resp.RespEntity;
import com.amazon.service.UserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/add-user")
    public RespEntity addUser(@RequestBody AddUserParam param) throws InterruptedException {
        String status =  userService.addUser(param);
        return RespEntity.success(status);
    }

    @GetMapping("/list-user")
    public RespEntity listUser(BasePageParam param){
        IPage<User> page = userService.listUser(param);
        return RespEntity.success(page);
    }

    @GetMapping("/get-user")
    public RespEntity getUser(String name){
        User user = userService.getUser(name);
        return RespEntity.success(user);
    }

    @PostMapping("/update-user")
    public RespEntity updateUser(@RequestBody AddUserParam param){
        String status = userService.updateUser(param);
        return RespEntity.success(status);
    }

    @PostMapping("/tian-ka")
    public RespEntity tianKa(@RequestBody AddUserParam param){
        String status = userService.tianKa(param);
        return RespEntity.success(status);
    }

    @PostMapping("/login-check-code")
    public RespEntity loginCheckCode(@RequestBody AddUserParam param){
        String status = userService.loginCheckCode(param);
        return RespEntity.success(status);
    }

    @PostMapping("/check")
    public RespEntity check(@RequestBody AddUserParam param){
        String status = userService.check(param);
        return RespEntity.success(status);
    }

    @GetMapping("/get-max-id")
    public RespEntity getMaxId(){
        JSONObject res = userService.getMaxId();
        return RespEntity.success(res);
    }


}
